package com.fjeld.client.gui.screens.node;

import com.fjeld.client.gui.util.factories.LabelFactory;
import com.fjeld.middleware.activemq.MessagesCellRenderer;
import com.fjeld.middleware.activemq.MessagesListener;
import com.fjeld.middleware.activemq.MessagesTableModel;
import com.fjeld.swingx.JTransparentPanel;
import com.fjeld.swingx.JTransparentScrollPane;
import com.fjeld.swingx.JTransparentTable;
import com.fjeld.swingx.table.ObserverTableModel;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: fjeld
 * Date: 29/12/2011
 * Time: 11:13
 *
 * Displays all messages seen on the listener
 */
public class MessagesView extends JTransparentPanel
{
    private ObserverTableModel tableModel;

    public MessagesView()
    {
        JLabel header = LabelFactory.createHeaderLabel("Messages seen:");

        tableModel = new MessagesTableModel();
        JTable table = new JTransparentTable(tableModel);
        table.setDefaultRenderer(Object.class, new MessagesCellRenderer());
        JTransparentScrollPane scrollPane = new JTransparentScrollPane(table);

        add(header, BorderLayout.NORTH);
        add(scrollPane, BorderLayout.CENTER);
    }

    public void addListener(MessagesListener ml)
    {
        tableModel.setData(ml.getMessageList());
    }
}
